import { defineStore } from 'pinia'
import useUserStore from "@/store/modules/user.js";
import userRouteStore from "@/store/modules/route.js";


let userMenuStore=defineStore("menu",{

    state:()=>{
        return {
            defaultOpens: null,
            defaultActive: null,
            menuPath:[]
        }
    },
    actions : {

        setDefaultActive(vueRoute){
            const routeStore=userRouteStore()
            let route=routeStore.routeMap[vueRoute.name]
            while(route){
                if(route.isMenu===1){
                   this.defaultActive=route.path
                    break
                }
                route=route.parent
            }

            this.setMenuPath(vueRoute)
        },
        setMenuPath(vueRoute){
            const resultMenu=[]
            const userStore = useUserStore()
            let routeStore=userRouteStore()
            let route=routeStore.routeMap[vueRoute.name]
            while(route){
                if(route.level!==1){
                    resultMenu.unshift(route)
                }
                route=route.parent
            }
            this.menuPath=resultMenu
        }
    },
    getters:{}

})

export default userMenuStore